package cn.qdhlm.frontendprocessor.controller;

import cn.qdhlm.frontendprocessor.common.helper.RocketMqProducer;
import cn.qdhlm.frontendprocessor.common.util.CodeUtil;
import cn.qdhlm.frontendprocessor.model.dto.CommandParamDTO;
import cn.qdhlm.frontendprocessor.model.memory.SendCommandResultMap;
import cn.qdhlm.frontendprocessor.service.CommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Name:MqttService
 * @description:
 * @author: xinY
 **/

@RestController
public class CommandController {
    @Autowired
    private CommandService service;
    @Autowired
    private RocketMqProducer producer;
    @GetMapping("/mqtt/cmd/{afn}/{fn}")
    public List<String> mqttCmd(CommandParamDTO commandParamDTO) {
        service.sendMqtt(commandParamDTO);
        return SendCommandResultMap.getAll();
    }

    @GetMapping("/mqtt-nb/cmd")
    public List<String> mqttNbCmd( CommandParamDTO commandParamDTO) {
        System.out.println("mqtt-nb controller");

        service.sendMqttNb(commandParamDTO);
        return SendCommandResultMap.getAll();
    }

    @GetMapping("/telecom-nb/cmd/{afn}/{fn}")
    public List<String> telecomNbCmd( CommandParamDTO commandParamDTO) {
        service.sendTelecomNb(commandParamDTO);
        return SendCommandResultMap.getAll();
    }


    // 测试负载接口
    @GetMapping("/test/{data}")
    public void pushData(@PathVariable("data") String data){
        System.out.println("pushdata .........." + data);
        producer.send("DeviceData","mqtt", CodeUtil.hexStringToByteArray(data));
        producer.send("DeviceData","nb-mqtt",CodeUtil.hexStringToByteArray(data));
    }
}
